﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace L4View.BusinessModel
{
    using Infrastructure;

    public class MonitorFactory : IMonitorFactory
    {
        private delegate IMessageMonitor CreateMessageMonitorDelegate();

        private readonly IDictionary<Guid, CreateMessageMonitorDelegate> _Id2CreateMethodMap;

        public MonitorFactory()
        {
            _Id2CreateMethodMap = new Dictionary<Guid, CreateMessageMonitorDelegate>();

            RegisterCreationMethods();
        }

        public IMessageMonitor CreateMonitorById(Guid uniqueId)
        {
            if (!_Id2CreateMethodMap.Keys.Contains(uniqueId))
                throw new NotSupportedException(
                    string.Format("No Monitor assigned with passed ID:{0}", uniqueId));

            return _Id2CreateMethodMap[uniqueId]();
        }

        private void RegisterCreationMethods()
        {
            _Id2CreateMethodMap.Add(SpyLogMonitor.SpyLogMonitor.Id, this.CreateSpyLogFile);
        }

        private IMessageMonitor CreateSpyLogFile()
        {
            return new SpyLogMonitor.SpyLogMonitor();
        }
    }
}
